package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;

public class AttendanceTypeDialogFragment extends DialogFragment {
  private int[] choiceIds =
      new int[] { R.string.all, R.string.sign_in, R.string.sign_out, R.string.sign_field_time };
  private String[] choiceStrings = new String[choiceIds.length];

  @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new OnClickListener() {
          @Override public void onClick(DialogInterface dialog, int which) {

            String type;
            switch (which) {
              case 0:
                type = "";
                break;
              case 1:
                type = "in";
                break;
              case 2:
                type = "out";
                break;
              case 3:
                type = "keep";
                break;
              default:
                type = "";
                break;
            }
            CustomerDialog content = new CustomerDialog(getChoiceName()[which], type);
            if (getTargetFragment() == null) return;
            Intent i = new Intent();
            i.putExtra(AttendanceSummaryQueryFragment.EXTRA_VALUE, content);
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);
            dialog.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
